﻿using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
using RxjhServer;
using RxjhServer.DbClss;
namespace RxjhServer
{
    public partial class CheckCopy : Form
    {
        private Button button1;
        private IContainer components = null;
        private GroupBox groupBox1;
        private GroupBox groupBox2;
        private MenuStrip menuStrip1;
        private RadioButton radioButton2;
        private RadioButton radioButton3;
        private RadioButton radioButton4;
        private RadioButton radioButton7;
        private TextBox textBox1;
        private ToolStripMenuItem 帮助ToolStripMenuItem;
        private DataTable 个人仓库;
        private DataTable 个人仓库1;
        private DataTable 人物自身;
        private DataTable 人物自身1;
        private ToolStripMenuItem 说明ToolStripMenuItem;
        private DataTable 综合仓库;
        private DataTable 综合仓库1;
        public CheckCopy()
        {
            this.InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            this.人物自身 = null;
            this.个人仓库 = null;
            this.综合仓库 = null;
            this.人物自身1 = null;
            this.个人仓库1 = null;
            this.综合仓库1 = null;
            if (World.allConnectedChars.Count > 0)
            {
                MessageBox.Show("有人物在线不能查询!", "提示");
            }
            else
            {
                this.SetText("开始查询....");
                this.button1.Enabled = false;
                string sqlCommand = string.Format("select FLD_ID,FLD_NAME,FLD_WEARITEM,FLD_ITEM from [TBL_人物数据]", new object[0]);
                string str2 = string.Format("select FLD_ID,FLD_NAME,FLD_ITEM from [TBL_个人仓库]", new object[0]);
                string str3 = string.Format("select FLD_ID,FLD_ITEM from [TBL_综合仓库]", new object[0]);
                this.人物自身 = DBA.GetDBToDataTable(sqlCommand, "GameServer");
                this.个人仓库 = DBA.GetDBToDataTable(str2, "GameServer");
                this.综合仓库 = DBA.GetDBToDataTable(str3, "GameServer");
                if (this.radioButton2.Checked || this.radioButton7.Checked)
                {
                    if (this.人物自身.Rows.Count != 0)
                    {
                        if (this.radioButton2.Checked)
                        {
                            for (int i = 0; i < this.人物自身.Rows.Count; i++)
                            {
                                byte[] src = (byte[])this.人物自身.Rows[i]["FLD_ITEM"];
                                string id = this.人物自身.Rows[i]["FLD_ID"].ToString();
                                string name = this.人物自身.Rows[i]["FLD_NAME"].ToString();
                                for (int j = 0; j < 36; j++)
                                {
                                    byte[] dst = new byte[4];
                                    Buffer.BlockCopy(src, j * 0x49, dst, 0, 4);
                                    int num3 = BitConverter.ToInt32(dst, 0);
                                    if (num3 != 0)
                                    {
                                        try
                                        {
                                            ThreadParameter state = new ThreadParameter(num3, id, name, 0);
                                            ThreadPool.QueueUserWorkItem(new WaitCallback(this.查物品), state);
                                        }
                                        catch (Exception exception)
                                        {
                                            this.SetText("查询背包线程出错" + exception.ToString());
                                        }
                                    }
                                }
                            }
                            this.SetText("查询完毕!!!!");
                        }
                        else
                        {
                            for (int k = 0; k < this.人物自身.Rows.Count; k++)
                            {
                                byte[] buffer3 = (byte[])this.人物自身.Rows[k]["FLD_WEARITEM"];
                                string str6 = this.人物自身.Rows[k]["FLD_ID"].ToString();
                                string str7 = this.人物自身.Rows[k]["FLD_NAME"].ToString();
                                for (int m = 0; m < 15; m++)
                                {
                                    byte[] buffer4 = new byte[4];
                                    Buffer.BlockCopy(buffer3, m * 0x49, buffer4, 0, 4);
                                    int num6 = BitConverter.ToInt32(buffer4, 0);
                                    if (num6 != 0)
                                    {
                                        try
                                        {
                                            ThreadParameter parameter2 = new ThreadParameter(num6, str6, str7, 1);
                                            ThreadPool.QueueUserWorkItem(new WaitCallback(this.查物品), parameter2);
                                        }
                                        catch (Exception exception2)
                                        {
                                            this.SetText("查询已穿装备线程出错" + exception2.ToString());
                                        }
                                    }
                                }
                            }
                            this.SetText("查询完毕!!!!");
                        }
                    }
                    this.人物自身.Dispose();
                }
                else if (this.radioButton3.Checked)
                {
                    if (this.个人仓库.Rows.Count != 0)
                    {
                        for (int n = 0; n < this.个人仓库.Rows.Count; n++)
                        {
                            byte[] buffer5 = (byte[])this.个人仓库.Rows[n]["FLD_ITEM"];
                            for (int num8 = 0; num8 < 60; num8++)
                            {
                                byte[] buffer6 = new byte[4];
                                string str8 = this.个人仓库.Rows[n]["FLD_ID"].ToString();
                                string str9 = this.个人仓库.Rows[n]["FLD_NAME"].ToString();
                                Buffer.BlockCopy(buffer5, num8 * 0x49, buffer6, 0, 4);
                                int num9 = BitConverter.ToInt32(buffer6, 0);
                                if (num9 != 0)
                                {
                                    try
                                    {
                                        ThreadParameter parameter3 = new ThreadParameter(num9, str8, str9, 2);
                                        ThreadPool.QueueUserWorkItem(new WaitCallback(this.查物品), parameter3);
                                    }
                                    catch (Exception exception3)
                                    {
                                        this.SetText("查询个人仓库线程出错" + exception3.ToString());
                                    }
                                }
                            }
                        }
                        this.SetText("查询完毕!!!!");
                    }
                    this.个人仓库.Dispose();
                }
                else
                {
                    if (this.综合仓库.Rows.Count != 0)
                    {
                        for (int num10 = 0; num10 < this.综合仓库.Rows.Count; num10++)
                        {
                            byte[] buffer7 = (byte[])this.综合仓库.Rows[num10]["FLD_ITEM"];
                            for (int num11 = 0; num11 < 60; num11++)
                            {
                                byte[] buffer8 = new byte[4];
                                string str10 = this.综合仓库.Rows[num10]["FLD_ID"].ToString();
                                Buffer.BlockCopy(buffer7, num11 * 0x49, buffer8, 0, 4);
                                int num12 = BitConverter.ToInt32(buffer8, 0);
                                if (num12 != 0)
                                {
                                    try
                                    {
                                        ThreadParameter parameter4 = new ThreadParameter(num12, str10, "", 3);
                                        ThreadPool.QueueUserWorkItem(new WaitCallback(this.查物品), parameter4);
                                    }
                                    catch (Exception exception4)
                                    {
                                        this.SetText("查询综合仓库线程出错" + exception4.ToString());
                                    }
                                }
                            }
                        }
                        this.SetText("查询完毕!!!!");
                    }
                    this.综合仓库.Dispose();
                }
                this.button1.Enabled = true;
            }
        }
        private void CheckCopy_FormClosing(object sender, FormClosingEventArgs e)
        {
            try
            {
                if (this.人物自身 != null)
                {
                    this.人物自身 = null;
                }
                if (this.人物自身1 != null)
                {
                    this.人物自身1 = null;
                }
                if (this.个人仓库 != null)
                {
                    this.个人仓库 = null;
                }
                if (this.个人仓库1 != null)
                {
                    this.个人仓库1 = null;
                }
                if (this.综合仓库 != null)
                {
                    this.综合仓库 = null;
                }
                if (this.综合仓库1 != null)
                {
                    this.综合仓库1 = null;
                }
            }
            catch
            {
            }
        }
        private void CheckCopy_Load(object sender, EventArgs e)
        {
            ThreadPool.SetMinThreads(100, 100);
        }
        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }
        private void InitializeComponent()
        {
            this.groupBox1 = new GroupBox();
            this.radioButton7 = new RadioButton();
            this.radioButton4 = new RadioButton();
            this.radioButton3 = new RadioButton();
            this.radioButton2 = new RadioButton();
            this.groupBox2 = new GroupBox();
            this.textBox1 = new TextBox();
            this.button1 = new Button();
            this.menuStrip1 = new MenuStrip();
            this.说明ToolStripMenuItem = new ToolStripMenuItem();
            this.帮助ToolStripMenuItem = new ToolStripMenuItem();
            this.groupBox1.SuspendLayout();
            this.groupBox2.SuspendLayout();
            this.menuStrip1.SuspendLayout();
            base.SuspendLayout();
            this.groupBox1.Controls.Add(this.radioButton7);
            this.groupBox1.Controls.Add(this.radioButton4);
            this.groupBox1.Controls.Add(this.radioButton3);
            this.groupBox1.Controls.Add(this.radioButton2);
            this.groupBox1.Location = new Point(0x21, 0x1b);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new Size(0x1f0, 0x3e);
            this.groupBox1.TabIndex = 0;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "查询类型";
            this.radioButton7.AutoSize = true;
            this.radioButton7.Location = new Point(0x5b, 30);
            this.radioButton7.Name = "radioButton7";
            this.radioButton7.Size = new Size(0x47, 0x10);
            this.radioButton7.TabIndex = 5;
            this.radioButton7.TabStop = true;
            this.radioButton7.Text = "已穿装备";
            this.radioButton7.UseVisualStyleBackColor = true;
            this.radioButton4.AutoSize = true;
            this.radioButton4.Location = new Point(0x11b, 30);
            this.radioButton4.Name = "radioButton4";
            this.radioButton4.Size = new Size(0x47, 0x10);
            this.radioButton4.TabIndex = 3;
            this.radioButton4.TabStop = true;
            this.radioButton4.Text = "综合仓库";
            this.radioButton4.UseVisualStyleBackColor = true;
            this.radioButton3.AutoSize = true;
            this.radioButton3.Location = new Point(0xbb, 30);
            this.radioButton3.Name = "radioButton3";
            this.radioButton3.Size = new Size(0x47, 0x10);
            this.radioButton3.TabIndex = 2;
            this.radioButton3.TabStop = true;
            this.radioButton3.Text = "个人仓库";
            this.radioButton3.UseVisualStyleBackColor = true;
            this.radioButton2.AutoSize = true;
            this.radioButton2.Location = new Point(0x13, 30);
            this.radioButton2.Name = "radioButton2";
            this.radioButton2.Size = new Size(0x2f, 0x10);
            this.radioButton2.TabIndex = 1;
            this.radioButton2.TabStop = true;
            this.radioButton2.Text = "背包";
            this.radioButton2.UseVisualStyleBackColor = true;
            this.groupBox2.Controls.Add(this.textBox1);
            this.groupBox2.Location = new Point(0x21, 0x66);
            this.groupBox2.Name = "groupBox2";
            this.groupBox2.Size = new Size(0x1f0, 0x182);
            this.groupBox2.TabIndex = 1;
            this.groupBox2.TabStop = false;
            this.groupBox2.Text = "查询记录";
            this.textBox1.Location = new Point(0x13, 20);
            this.textBox1.Multiline = true;
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new Size(0x1ca, 0x15b);
            this.textBox1.TabIndex = 0;
            this.button1.Location = new Point(0x1b3, 0x1ee);
            this.button1.Name = "button1";
            this.button1.Size = new Size(0x4b, 0x17);
            this.button1.TabIndex = 4;
            this.button1.Text = "开始查询";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new EventHandler(this.button1_Click);
            this.menuStrip1.Items.AddRange(new ToolStripItem[] { this.说明ToolStripMenuItem });
            this.menuStrip1.Location = new Point(0, 0);
            this.menuStrip1.Name = "menuStrip1";
            this.menuStrip1.Size = new Size(0x237, 0x18);
            this.menuStrip1.TabIndex = 5;
            this.menuStrip1.Text = "menuStrip1";
            this.说明ToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { this.帮助ToolStripMenuItem });
            this.说明ToolStripMenuItem.Name = "说明ToolStripMenuItem";
            this.说明ToolStripMenuItem.Size = new Size(0x29, 20);
            this.说明ToolStripMenuItem.Text = "说明";
            this.帮助ToolStripMenuItem.Name = "帮助ToolStripMenuItem";
            this.帮助ToolStripMenuItem.Size = new Size(0x5e, 0x16);
            this.帮助ToolStripMenuItem.Text = "帮助";
            this.帮助ToolStripMenuItem.Click += new EventHandler(this.帮助ToolStripMenuItem_Click);
            base.AutoScaleDimensions = new SizeF(6f, 12f);
            base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            base.ClientSize = new Size(0x237, 0x211);
            base.Controls.Add(this.button1);
            base.Controls.Add(this.groupBox2);
            base.Controls.Add(this.groupBox1);
            base.Controls.Add(this.menuStrip1);
            base.MainMenuStrip = this.menuStrip1;
            base.Name = "CheckCopy";
            this.Text = "查复制";
            base.Load += new EventHandler(this.CheckCopy_Load);
            base.FormClosing += new FormClosingEventHandler(this.CheckCopy_FormClosing);
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            this.groupBox2.ResumeLayout(false);
            this.groupBox2.PerformLayout();
            this.menuStrip1.ResumeLayout(false);
            this.menuStrip1.PerformLayout();
            base.ResumeLayout(false);
            base.PerformLayout();
        }
        private void SetText(string s)
        {
            if (this.textBox1.InvokeRequired)
            {
                MyInvoke method = new MyInvoke(this.SetText);
                base.Invoke(method, new object[] { "\r\n" + s });
            }
            else
            {
                this.textBox1.Text = this.textBox1.Text + "\r\n" + s;
            }
        }
        private void 帮助ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("数据量大的查询时间比较长,必须是停服维护(关闭LoginServer且无玩家登录)才能查询", "帮助");
        }
        private void 查物品(object ParObject)
        {
            ThreadParameter parameter = (ThreadParameter)ParObject;
            string str = "";
            string sqlCommand = string.Format("select FLD_ID,FLD_NAME,FLD_WEARITEM,FLD_ITEM from [TBL_人物数据] where FLD_NAME<>'{0}'", parameter.name);
            string str3 = string.Format("select FLD_ID,FLD_NAME,FLD_ITEM from [TBL_个人仓库] where FLD_NAME<>'{0}'", parameter.name);
            string str4 = string.Format("select FLD_ID,FLD_ITEM from [TBL_综合仓库] where FLD_ID<>'{0}'", parameter.id);
            switch (parameter.类型)
            {
                case 0:
                    str = "背包";
                    break;
                case 1:
                    str = "已穿装备";
                    break;
                case 2:
                    str = "个人仓库";
                    break;
                case 3:
                    sqlCommand = "select FLD_ID,FLD_NAME,FLD_WEARITEM,FLD_ITEM from [TBL_人物数据]";
                    str3 = "select FLD_ID,FLD_NAME,FLD_ITEM from [TBL_个人仓库]";
                    str = "综合仓库";
                    break;
            }
            this.人物自身1 = DBA.GetDBToDataTable(sqlCommand, "GameServer");
            this.个人仓库1 = DBA.GetDBToDataTable(str3, "GameServer");
            this.综合仓库1 = DBA.GetDBToDataTable(str4, "GameServer");
            if (this.人物自身1.Rows.Count != 0)
            {
                for (int i = 0; i < this.人物自身1.Rows.Count; i++)
                {
                    byte[] src = (byte[])this.人物自身1.Rows[i]["FLD_ITEM"];
                    byte[] buffer2 = (byte[])this.人物自身1.Rows[i]["FLD_WEARITEM"];
                    this.人物自身1.Rows[i]["FLD_ID"].ToString();
                    string str5 = this.人物自身1.Rows[i]["FLD_NAME"].ToString();
                    for (int j = 0; j < 0x24; j++)
                    {
                        byte[] dst = new byte[4];
                        Buffer.BlockCopy(src, j * 0x49, dst, 0, 4);
                        int num3 = BitConverter.ToInt32(dst, 0);
                        if ((num3 != 0) && (num3 == parameter.全局ID))
                        {
                            this.SetText("发现复制装备,物品全局ID[" + parameter.全局ID.ToString() + "],在人物【" + str5 + "】的背包栏和人物【" + parameter.name + "】的" + str);
                        }
                    }
                    for (int k = 0; k < 15; k++)
                    {
                        byte[] buffer4 = new byte[4];
                        Buffer.BlockCopy(buffer2, k * 0x49, buffer4, 0, 4);
                        int num5 = BitConverter.ToInt32(buffer4, 0);
                        if ((num5 != 0) && (num5 == parameter.全局ID))
                        {
                            this.SetText("发现复制装备,物品全局ID[" + parameter.全局ID.ToString() + "],在人物【" + str5 + "】的已穿装备栏和人物【" + parameter.name + "】的" + str);
                        }
                    }
                }
            }
            this.人物自身1.Dispose();
            if (this.个人仓库1.Rows.Count != 0)
            {
                for (int m = 0; m < this.个人仓库1.Rows.Count; m++)
                {
                    byte[] buffer5 = (byte[])this.个人仓库1.Rows[m]["FLD_ITEM"];
                    string str6 = this.个人仓库1.Rows[m]["FLD_NAME"].ToString();
                    for (int n = 0; n < 60; n++)
                    {
                        byte[] buffer6 = new byte[4];
                        Buffer.BlockCopy(buffer5, n * 0x49, buffer6, 0, 4);
                        int num8 = BitConverter.ToInt32(buffer6, 0);
                        if ((num8 != 0) && (num8 == parameter.全局ID))
                        {
                            this.SetText("发现复制装备,物品全局ID[" + parameter.全局ID.ToString() + "],在人物【" + str6 + "】的个人仓库和人物【" + parameter.name + "】的" + str);
                        }
                    }
                }
            }
            this.个人仓库1.Dispose();
            if (this.综合仓库1.Rows.Count != 0)
            {
                for (int num9 = 0; num9 < this.综合仓库1.Rows.Count; num9++)
                {
                    byte[] buffer7 = (byte[])this.综合仓库1.Rows[num9]["FLD_ITEM"];
                    string str7 = this.综合仓库1.Rows[num9]["FLD_ID"].ToString();
                    for (int num10 = 0; num10 < 60; num10++)
                    {
                        byte[] buffer8 = new byte[4];
                        Buffer.BlockCopy(buffer7, num10 * 0x49, buffer8, 0, 4);
                        int num11 = BitConverter.ToInt32(buffer8, 0);
                        if ((num11 != 0) && (num11 == parameter.全局ID))
                        {
                            this.SetText("发现复制装备,物品全局ID[" + parameter.全局ID.ToString() + "],在帐号【" + str7 + "】的综合仓库和人物【" + parameter.name + "】的" + str);
                        }
                    }
                }
            }
            this.综合仓库1.Dispose();
     
        }
        public delegate void MyInvoke(string str);
    }
}

